<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>连接历史 - OpenVPN 监控系统</title>
    <link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
</head>
<body>
    <div class="container">
        <header class="header">
            <h1><i class="fas fa-shield-alt"></i> OpenVPN 监控系统</h1>
            <nav class="nav">
                <a href="/" class="nav-link"><i class="fas fa-home"></i> 首页</a>
                <a href="/online" class="nav-link"><i class="fas fa-users"></i> 在线用户</a>
                <a href="/history" class="nav-link active"><i class="fas fa-history"></i> 连接历史</a>
            </nav>
        </header>

        <main class="main">
            <div class="page-header">
                <h2><i class="fas fa-history"></i> 连接历史记录</h2>
                <div class="page-actions">
                    <button class="refresh-btn" onclick="refreshHistory()">
                        <i class="fas fa-sync-alt"></i> 刷新
                    </button>
                </div>
            </div>

            <!-- 过滤和查询区域 -->
            <div class="card">
                <div class="card-header">
                    <h3><i class="fas fa-filter"></i> 查询过滤</h3>
                </div>
                <div class="card-content">
                    <div class="filter-form">
                        <div class="filter-row">
                            <div class="filter-group">
                                <label for="username-filter">用户名:</label>
                                <input type="text" id="username-filter" placeholder="输入用户名进行查询...">
                            </div>
                            <div class="filter-group">
                                <label for="start-date">开始日期:</label>
                                <input type="date" id="start-date">
                            </div>
                            <div class="filter-group">
                                <label for="end-date">结束日期:</label>
                                <input type="date" id="end-date">
                            </div>
                            <div class="filter-actions">
                                <button class="btn btn-primary" onclick="applyFilters()">
                                    <i class="fas fa-search"></i> 查询
                                </button>
                                <button class="btn btn-secondary" onclick="clearFilters()">
                                    <i class="fas fa-times"></i> 清空
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 用户统计区域 -->
            <div class="card" id="user-stats-card" style="display: none;">
                <div class="card-header">
                    <h3><i class="fas fa-user-chart"></i> 用户统计</h3>
                </div>
                <div class="card-content">
                    <div class="user-stats">
                        <div class="stat-card">
                            <div class="stat-icon">
                                <i class="fas fa-plug"></i>
                            </div>
                            <div class="stat-info">
                                <h4>连接次数</h4>
                                <p id="user-connections">0</p>
                            </div>
                        </div>
                        <div class="stat-card">
                            <div class="stat-icon">
                                <i class="fas fa-clock"></i>
                            </div>
                            <div class="stat-info">
                                <h4>总连接时长</h4>
                                <p id="user-total-duration">0秒</p>
                            </div>
                        </div>
                        <div class="stat-card">
                            <div class="stat-icon">
                                <i class="fas fa-clock"></i>
                            </div>
                            <div class="stat-info">
                                <h4>平均连接时长</h4>
                                <p id="user-avg-duration">0秒</p>
                            </div>
                        </div>
                        <div class="stat-card">
                            <div class="stat-icon">
                                <i class="fas fa-download"></i>
                            </div>
                            <div class="stat-info">
                                <h4>总接收流量</h4>
                                <p id="user-total-received">0 B</p>
                            </div>
                        </div>
                        <div class="stat-card">
                            <div class="stat-icon">
                                <i class="fas fa-upload"></i>
                            </div>
                            <div class="stat-info">
                                <h4>总发送流量</h4>
                                <p id="user-total-sent">0 B</p>
                            </div>
                        </div>
                        <div class="stat-card">
                            <div class="stat-icon">
                                <i class="fas fa-exchange-alt"></i>
                            </div>
                            <div class="stat-info">
                                <h4>总流量</h4>
                                <p id="user-total-traffic">0 B</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 总体统计区域 -->
            <div class="card">
                <div class="card-header">
                    <h3><i class="fas fa-chart-bar"></i> 总体统计</h3>
                </div>
                <div class="card-content">
                    <div class="history-stats">
                        <div class="stat-card">
                            <div class="stat-icon">
                                <i class="fas fa-users"></i>
                            </div>
                            <div class="stat-info">
                                <h4>总连接用户</h4>
                                <p id="total-users">0</p>
                            </div>
                        </div>
                        <div class="stat-card">
                            <div class="stat-icon">
                                <i class="fas fa-network-wired"></i>
                            </div>
                            <div class="stat-info">
                                <h4>总连接次数</h4>
                                <p id="total-connections">0</p>
                            </div>
                        </div>
                        <div class="stat-card">
                            <div class="stat-icon">
                                <i class="fas fa-clock"></i>
                            </div>
                            <div class="stat-info">
                                <h4>平均连接时长</h4>
                                <p id="avg-duration">0分钟</p>
                            </div>
                        </div>
                        <div class="stat-card">
                            <div class="stat-icon">
                                <i class="fas fa-exchange-alt"></i>
                            </div>
                            <div class="stat-info">
                                <h4>总流量使用</h4>
                                <p id="total-traffic">0 B</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 历史记录表格 -->
            <div class="card">
                <div class="card-header">
                    <h3><i class="fas fa-list"></i> 历史连接记录</h3>
                    <span class="record-count" id="record-count">0 条记录</span>
                </div>
                <div class="card-content">
                    <div class="table-container">
                        <table class="data-table">
                            <thead>
                                <tr>
                                    <th><i class="fas fa-user"></i> 用户名</th>
                                    <th><i class="fas fa-network-wired"></i> 虚拟地址</th>
                                    <th><i class="fas fa-map-marker-alt"></i> 地理位置</th>
                                    <th><i class="fas fa-calendar"></i> 连接开始时间</th>
                                    <th><i class="fas fa-calendar-times"></i> 断开时间</th>
                                </tr>
                            </thead>
                            <tbody id="history-table">
                                <tr>
                                    <td colspan="8" class="loading">
                                        <i class="fas fa-spinner fa-spin"></i>
                                        正在加载数据...
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </main>

        <div class="pagination-container">
            <div class="pagination-controls">
                <button id="prev-page" class="btn btn-secondary" onclick="changePage(-1)"><i class="fas fa-angle-left"></i> 上一页</button>
                <span id="pagination-info">第 1 / 1 页</span>
                <button id="next-page" class="btn btn-secondary" onclick="changePage(1)">下一页 <i class="fas fa-angle-right"></i></button>
                <span class="per-page-label">每页显示</span>
                <select id="per-page-select" onchange="changePerPage()">
                    <option value="10">10</option>
                    <option value="50">50</option>
                    <option value="100">100</option>
                </select>
                <span>条</span>
            </div>
        </div>

        <footer class="footer">
            <p>&copy; 2024 OpenVPN 监控系统. 服务器: {{ config.OPENVPN_HOST }}:{{ config.OPENVPN_PORT }}</p>
        </footer>
    </div>

    <script src="{{ url_for('static', filename='js/history.js') }}"></script>
</body>
</html> 